Utility functions to work with the DOM events, used by Leaflet internally.
Functions
Function | Returns | Description |
---|---|---|
on(<HTMLElement> el, <String> types, <Function> fn, <Object> context?) | this | Adds a listener function (fn ) to a particular DOM event type of the element el . You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick' ).向元素el的特定DOM事件类型添加侦听器函数(fn)。您可以选择指定侦听器的上下文(this关键字将指向的对象)。您还可以传递几个空格分隔的类型(例如“click dblclick”)。 |
on(<HTMLElement> el, <Object> eventMap, <Object> context?) | this | Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove} 添加一组类型/侦听器对,例如{click:onClick,mousemove:onMouseMove} |
off(<HTMLElement> el, <String> types, <Function> fn, <Object> context?) | this | Removes a previously added listener function. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.删除以前添加的侦听器函数。请注意,如果您将自定义上下文传递给on,则必须将相同的上下文传递给off才能删除侦听器。 |
off(<HTMLElement> el, <Object> eventMap, <Object> context?) | this | Removes a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove} 删除一组类型/侦听器对,例如{click:onClick,mousemove:onMouseMove} |
off(<HTMLElement> el, <String> types) | this | Removes all previously added listeners of given types. 删除所有以前添加的给定类型的侦听器。 |
off(<HTMLElement> el) | this | Removes all previously added listeners from given HTMLElement 从给定的HTMLElement中删除所有以前添加的侦听器 |
stopPropagation(<DOMEvent> ev) | this | Stop the given event from propagation to parent elements. Used inside the listener functions:L.DomEvent.on(div, 'click', function (ev) { L.DomEvent.stopPropagation(ev); }); 停止给定事件传播到父元素。在侦听器函数中使用:L.DomEvent.on(div,’click’,function(ev){L.DomEvent.stopPropagation(ev);}); |
disableScrollPropagation( <HTMLElement> el) | this | Adds stopPropagation to the element’s 'wheel' events (plus browser variants).将stopPropagation添加到元素的“wheel”事件(加上浏览器变量)。 |
disableClickPropagation( <HTMLElement> el) | this | Adds stopPropagation to the element’s 'click' , 'dblclick' , 'contextmenu' , 'mousedown' and 'touchstart' events (plus browser variants).将stopPropagation添加到元素的“click”、“dblclick”、“contextmenu”、“mousedown”和“touchstart”事件(以及浏览器变体)。 |
preventDefault(<DOMEvent> ev) | this | Prevents the default action of the DOM Event ev from happening (such as following a link in the href of the a element, or doing a POST request with page reload when a <form> is submitted). Use it inside listener functions.防止DOM Event ev的默认操作发生(例如,在元素的href中执行链接,或在提交<form>时执行POST请求并重新加载页面)。在侦听器函数中使用它。 |
stop(<DOMEvent> ev) | this | Does stopPropagation and preventDefault at the same time.同时停止传播和防止默认。 |
getPropagationPath(<DOMEvent> ev) | Array | Compatibility polyfill for Event.composedPath() . Returns an array containing the HTMLElement s that the given DOM event should propagate to (if not stopped).Event.composedPath()的兼容性polyfill。返回一个数组,该数组包含给定DOM事件应传播到的HTMLElements(如果未停止)。 |
getMousePosition(<DOMEvent> ev, <HTMLElement> container?) | Point | Gets normalized mouse position from a DOM event relative to the container (border excluded) or to the whole page if not specified.从DOM事件获取相对于容器(不包括边框)或整个页面(如果未指定)的标准化鼠标位置。 |
getWheelDelta(<DOMEvent> ev) | Number | Gets normalized wheel delta from a wheel DOM event, in vertical pixels scrolled (negative if scrolling down). Events from pointing devices without precise scrolling are mapped to a best guess of 60 pixels. 从轮子DOM事件获取标准化的轮子增量,以滚动的垂直像素为单位(如果向下滚动则为负值)。来自没有精确滚动的定点设备的事件被映射到60个像素的最佳猜测。 |
addListener(…) | this | Alias to L.DomEvent.on |
removeListener(…) | this | Alias to L.DomEvent.off |